

using System.Linq;
using Abp.Authorization;
using Abp.Configuration.Startup;
using Abp.Localization;
using Abp.MultiTenancy;
using Yozeev.Authorization;

namespace Yozeev.BusinessLogic.Authorization
{
    /// <summary>
    /// 权限配置都在这里。
    /// 给权限默认设置服务
    /// See <see cref="TicketIntroducePermissions" /> for all permission names. TicketIntroduce
    ///</summary>
    public class TicketIntroduceAuthorizationProvider : AuthorizationProvider
    {
        private readonly bool _isMultiTenancyEnabled;

		public TicketIntroduceAuthorizationProvider()
		{

		}

        public TicketIntroduceAuthorizationProvider(bool isMultiTenancyEnabled)
        {
            _isMultiTenancyEnabled = isMultiTenancyEnabled;
        }

        public TicketIntroduceAuthorizationProvider(IMultiTenancyConfig multiTenancyConfig)
        {
            _isMultiTenancyEnabled = multiTenancyConfig.IsEnabled;
        }

		public override void SetPermissions(IPermissionDefinitionContext context)
		{
			// 在这里配置了TicketIntroduce 的权限。
			var pages = context.GetPermissionOrNull(AppLtmPermissions.Pages) ?? context.CreatePermission(AppLtmPermissions.Pages, L("Pages"));

			var administration = pages.Children.FirstOrDefault(p => p.Name == AppLtmPermissions.Pages_Administration) ?? pages.CreateChildPermission(AppLtmPermissions.Pages_Administration, L("Administration"));

			var entityPermission = administration.CreateChildPermission(TicketIntroducePermissions.Node , L("TicketIntroduce"));
			entityPermission.CreateChildPermission(TicketIntroducePermissions.Query, L("QueryTicketIntroduce"));
			entityPermission.CreateChildPermission(TicketIntroducePermissions.Create, L("CreateTicketIntroduce"));
			entityPermission.CreateChildPermission(TicketIntroducePermissions.Edit, L("EditTicketIntroduce"));
			entityPermission.CreateChildPermission(TicketIntroducePermissions.Delete, L("DeleteTicketIntroduce"));
			entityPermission.CreateChildPermission(TicketIntroducePermissions.BatchDelete, L("BatchDeleteTicketIntroduce"));
			entityPermission.CreateChildPermission(TicketIntroducePermissions.ExportExcel, L("ExportExcelTicketIntroduce"));


		}

		private static ILocalizableString L(string name)
		{
			return new LocalizableString(name, AppConsts.LocalizationSourceName);
		}
    }
}